update_hosts(){
    local host_path=${1:-"hosts"}
    local host_url=${2:-""}
    local reg=${3:-""}
    
    # 检查文件是否存在，若不存在则创建
    if [[ ! -f "${host_path}" ]]; then
        local dir_path=$(dirname "${host_path}")
        # 如果目录不存在则创建目录
        if [[ ! -d "${dir_path}" ]]; then
            sudo mkdir -p "${dir_path}"
            echo "已创建目录：${dir_path}"
        fi
        sudo touch "${host_path}"
        echo "已创建文件：${host_path}"
    fi

    sudo curl -f ${host_url} | sudo tee "${host_path}" >/dev/null
        
}

# 更新GitHub Hosts
update_hosts hosts_github https://raw.hellogithub.com/hosts 
# 更新Zero Hosts
update_hosts hosts_zero https://someonewhocares.org/hosts/zero/hosts  

